<?php
/**
 * 申请提现
 */
require_once(dirname(__FILE__).'/config.php');
CheckRank(0,0);
$menutype = 'mydede';
$menutype_son = 'extract';

$r = $dsql->GetOne("SELECT certification FROM `#@__member` WHERE mid='{$cfg_ml->M_ID}'");
$rz = $r['certification'];
if($rz == 0)
{
	ShowMsg('要使用提现功能，您必须先进行身份认证','certification.php',0,8);
	exit;
}
else if($rz == 1)
{
	ShowMsg('您的身份认证正在审核中，暂时不能使用提现功能！','certification.php',0,8);
	exit;
}
else if($rz == 2)
{
	ShowMsg('您的身份认证没有通过审核，暂时不能使用提现功能！','certification.php',0,8);
	exit;
}

if($type == 'tx')
{
	if($shue <= 0)
	{
		ShowMsg('请输入大于0的提现数额','-1');
		exit();
	}
	else
	{
		$shues = $shue;
		$shue = $shue * $cfg_scsy;
		$row = $dsql->GetOne("SELECT money FROM `#@__member` WHERE mid='{$cfg_ml->M_ID}'");
		if($shue > $row['money'])
		{
			ShowMsg('提现数额不能大于您的金币数额','-1');
			exit();
		}
		else
		{
			//生成提现txid
			$txid = $dsql->GetOne("SELECT max(aid) FROM `#@__member_operation`");
			$txid = $txid["max(aid)"]+1;
			
			$money = "<font>-$shue</font>";
			$pnames = "<font>提现</font>";
            $inquery = "INSERT INTO `#@__member_operation`(arcid,mid,oldinfo,money,mtime,txid,buyid,product,pname,sta)
                  VALUES ('0','".$cfg_ml->M_ID."','申请提现','$money','".time()."', '$txid','tixian', 'archive','$pnames', 0); ";
            //记录定单
            if( !$dsql->ExecuteNoneQuery($inquery) )
            {
                ShowMsg('记录定单失败, 请返回', '-1');
                exit(0);
            }
            //扣除金币
            $dsql->ExecuteNoneQuery("UPDATE `#@__member` SET money = money - $shues WHERE mid='".$cfg_ml->M_ID."'");
			
			
			//个人信息
			$zsinfo = $dsql->GetOne("SELECT zuname,uzfb FROM `#@__member_person` WHERE mid='{$cfg_ml->M_ID}'");
			
			$row = $dsql->GetOne("SELECT userid FROM `#@__member` WHERE mid='1'");
			$uid = $row['userid'];
			
			$subject="用户[".$cfg_ml->M_LoginID."]申请了金币提现";
			$content="本次提现金币为".$shues."，计算为人名币等于".$shue."元--姓名:".$zsinfo['zuname'].",支付宝帐号：".$zsinfo['uzfb']."";
			$dsql->ExecuteNoneQuery("INSERT INTO `#@__member_pms`(floginid,fromid,toid,tologinid,folder,subject,sendtime,writetime,hasview,isadmin,message,contesfs,lxlx,type,txid) VALUES ('".$cfg_ml->M_LoginID."','".$cfg_ml->M_ID."','1','$uid','inbox','".$subject."','".time()."','".time()."','0','0','".$content."','','','1','$txid'); ");
			
			ShowMsg('提现申请成功，等待管理员审核','extract_op.php');
			exit();
		}
	}
}

$tpl = new DedeTemplate();
$tpl->LoadTemplate(DEDEMEMBER.'/templets/extract.htm');
$tpl->Display();